﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using MySql.Data.MySqlClient;


/// <summary>
/// Summary description for WebServiceExpenses
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
 [System.Web.Script.Services.ScriptService]
public class WebServiceExpenses : System.Web.Services.WebService
{

    public WebServiceExpenses()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public string HelloWorld()
    {
        return "Hello World";
    }

    [WebMethod]
    //[System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Xml)]
    public List<Exp> GetExpensesData()
    {

        MySqlConnection con = new MySqlConnection("Server=184.106.222.177;Database=exp;Uid=exp;Pwd=exp123;");
        DataSet ds = new DataSet();
        MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM expenses", con);
        da.Fill(ds);

        DataTable dt = ds.Tables[0];

        List<Exp> Exps = new List<Exp>();
        foreach (DataRow dr in dt.Rows)
        {
            Exp ObjExp = new Exp();
            ObjExp.ExpID = dr["ExpID"].ToString();
            ObjExp.Category = dr["Category"].ToString();
            ObjExp.Description = dr["Description"].ToString();
            ObjExp.Amount = dr["Amount"].ToString();
            Exps.Add(ObjExp);
        }
        return Exps;
    }

}

